package cn.sh.library.mgts.sparql;

import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.stream.Collectors;

import org.apache.commons.io.FileUtils;
import org.apache.commons.io.IOUtils;
import org.springframework.core.io.ClassPathResource;
import org.springframework.util.ResourceUtils;
import org.springframework.util.StreamUtils;

public enum ConstructQuery {
	CONSTRUCT_JP_WORKS("jp/CONSTRUCT_JP_WORKS.txt"),
	CONSTRUCT_JP_WORKS_WITHOUT_ITEM("jp/CONSTRUCT_JP_WORKS_WITHOUT_ITEM.txt"),
	CONSTRUCT_MGTS_CONTRIBUTION_INS("jp/CONSTRUCT_MGTS_CONTRIBUTION_INS.txt"),
	CONSTRUCT_MGTS_CONTRIBUTION_WORK("jp/CONSTRUCT_MGTS_CONTRIBUTION_WORK.txt"),
	CONSTRUCT_MGTS_TITLE_PNY("jp/CONSTRUCT_MGTS_TITLE_PNY.txt"),
	CONSTRUCT_MGTS_TITLE("jp/CONSTRUCT_MGTS_TITLE.txt"),
	CONSTRUCT_MGTS_RESEDIPRO_INS("jp/CONSTRUCT_MGTS_RESEDIPRO.txt"),
	CONSTRUCT_MGTS_INSBUCHONG("jp/CONSTRUCT_MGTS_INS_BUCHONG.txt"),
	CONSTRUCT_MGTS_WORKLANG("jp/CONSTRUCT_MGTS_WORKLANG.txt"),
	CONSTRUCT_MGTS_PROANDPUB("jp/CONSTRUCT_MGTS_INS_PROANDPUB.txt"),
	CONSTRUCT_MGTS_INS_CLASSPORTION("jp/CONSTRUCT_MGTS_INS_CLASSPORTION.txt")

	;
	
	protected String filename;

	ConstructQuery(String filename) {
		this.filename = filename;
	}

	@Override
	public String toString() {
		try {
			return FileUtils.readFileToString(ResourceUtils.getFile("classpath:"+"rdfSparql/" + this.filename), "UTF-8") ;
//			ClassPathResource resource = new ClassPathResource("classpath:"+"rdfSparql/" + this.filename);
//			
//			return IOUtils.readLines(resource.getInputStream(), "UTF-8").stream().collect(Collectors.joining(" "));
//			return FileUtils.readFileToString(resource.getFile(), "UTF-8") ;
		} catch (FileNotFoundException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return "";
	}

	/**
	 * Query with formatting
	 * 
	 * @param args
	 * @return
	 */
	public String toString(Object... args) {
		return String.format(toString(), args);
	}
	
	public static void main(String[] args) {
		System.out.println(ConstructQuery.CONSTRUCT_JP_WORKS.toString("http://data.library.sh.cn/gj/resource/instance/1hc5s56g36r2ww2n"));
		
	}
}
